import { createSlice } from "@reduxjs/toolkit";

export const todosSlice = createSlice({
  name: 'todos',
  initialState: [],
  reducers:{//接受action和state作为参数
    add(state, {payload: {text, id}}) {
      state.push({
        id, text, completed: false
      })
    },
    toggle(state, {payload: {id}}) {
    },
    del(state, {payload: index}) {
      state.splice(index, 1)
    }
  }
})
export const todosReducer = todosSlice.reducer
export const {add, del} = todosSlice.actions
export const todosSelector = state => state.todos